$.validator.methods.notEqual = function(value, element, param) {
	return value != param;
};
$.validator.methods.commune = function(value,element,param){
	alert(element.id);
	return true;
}
$(window).ready(function(){
	$("#commune").zipplugin();
	$("#expertises").ddlstackable();
	
	
	var validator = $("#trainingform").submit(function() {
		// update underlying textarea before submit validation
		tinyMCE.triggerSave();
	}).validate({
		ignore:"",
		rules: {
			trainingName:{required:true},
			trainingPayment:{required:true},
			trainingDetails:{required:true,commune:true}
		},
		messages:{},
		errorPlacement: function(label, element) {
			// position error label after generated textarea
			if (element.is("textarea")) {
				label.insertBefore(element.next());
			} else {
				label.insertAfter(element)
			}
		}
	});
	validator.focusInvalid = function() {
		// put focus on tinymce on submit validation
		if( this.settings.focusInvalid ) {
			try {
				var toFocus = $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []);
				if (toFocus.is("textarea")) {
					tinyMCE.get(toFocus.attr("id")).focus();
				} else {
					toFocus.filter(":visible").focus();
				}
			} catch(e) {
				// ignore IE throwing errors when focusing hidden elements
			}
		}
	}
	
	/*$("#category").change(function(event){
		event.stopImmediatePropagation();
		$("#subcategory").empty();
		$("select option:selected").each(function () {
            var parentid=$(this).val();
            var url = "http://bestcoming.localhost/training/categories/parentid/"+parentid+"/format/json";
            $.ajax({
				type:"GET",
				url : url,
				success:function(msg) {var myObjt = jQuery.parseJSON(msg.output);
				   for (var i = 0;i<myObjt.length;i++) {
					   var option = $("<option></option>");
					   option.attr("value",myObjt[i].id);
					   option.text(myObjt[i].name);
					   //var option = '<option value="'+myObjt[i].id+'">'+myObjt[i].name+'</option>';
	     			   $("#subcategory").append(option);
					}
				   
				   }
                });
		});
});*/
});